﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MaxStudio.Concrete.DBUtility;
using MaxStudio.Concrete.Server.Dao;
using MaxStudio.Concrete.Server.Interface; 

namespace MaxStudio.Concrete.Server.Service
{
    public class RPTSchoolConcreteTestService : ServiceHandle, IRPTSchoolConcreteTest
    {
        #region IRPTSchoolConcreteTest Members

        public OperationResult<List<tb_RPT_SchoolConcreteTest>> GetAllSchoolConcreteTest()
        {
            OperationResult<List<tb_RPT_SchoolConcreteTest>> result = new OperationResult<List<tb_RPT_SchoolConcreteTest>>();
            List<tb_RPT_SchoolConcreteTest> list = new List<tb_RPT_SchoolConcreteTest>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetAllSchoolConcreteTest();
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_RPT_SchoolConcreteTest>> GetSchoolConcreteTestByContition(string strProjectName, string strStrengtGrade )
        {
            OperationResult<List<tb_RPT_SchoolConcreteTest>> result = new OperationResult<List<tb_RPT_SchoolConcreteTest>>();
            List<tb_RPT_SchoolConcreteTest> list = new List<tb_RPT_SchoolConcreteTest>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetSchoolConcreteTestByContition(  strProjectName,   strStrengtGrade );
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_RPT_SchoolConcreteTest> GetSchoolConcreteTestById(int id)
        {
            ConcreteDaoDataContext dataContext = getDateContext();
            OperationResult<tb_RPT_SchoolConcreteTest> result = new OperationResult<tb_RPT_SchoolConcreteTest>();
            tb_RPT_SchoolConcreteTest schoolConcreteTest;
            try
            {
                schoolConcreteTest = dataContext.GetSchoolConcreteTestById(id);
                if (schoolConcreteTest == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = schoolConcreteTest;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_RPT_SchoolConcreteTest> CreateSchoolConcreteTest(tb_RPT_SchoolConcreteTest entity)
        {
            OperationResult<tb_RPT_SchoolConcreteTest> result = new OperationResult<tb_RPT_SchoolConcreteTest>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.CreateSchoolConcreteTest(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RPT_SchoolConcreteTest> ModifySchoolConcreteTest(tb_RPT_SchoolConcreteTest entity)
        {
            OperationResult<tb_RPT_SchoolConcreteTest> result = new OperationResult<tb_RPT_SchoolConcreteTest>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.ModifySchoolConcreteTest(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RPT_SchoolConcreteTest> DeleteSchoolConcreteTest(tb_RPT_SchoolConcreteTest entity)
        {
            OperationResult<tb_RPT_SchoolConcreteTest> result = new OperationResult<tb_RPT_SchoolConcreteTest>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.DeleteSchoolConcreteTest(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        #endregion
    }
}
